/*
 * All right reserved@Raygo 2022~2030
 */

package com.raygo.runner.core.entity;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

import com.raygo.runner.core.command.CmdParam;
import com.raygo.runner.core.command.Command;

/**
 * 步骤节点
 *
 * @author Raygo
 * @since 2022年8月6日
 */
public class StepTreeNode {
    /**
     * 序号
     */
    private int index;
    /**
     * GUID
     */
    private String guid;
    /**
     * 名称
     */
    private String name;
    /**
     * 描述
     */
    private String desc;
    /**
     * 使能
     */
    private boolean enable;
    /**
     * 关键项
     */
    private boolean key;
    /**
     * 模拟
     */
    private boolean mock;
    /**
     * 重试次数
     */
    private int retry;
    /**
     * 命令
     */
    private Command command;
    /**
     * 输入参数
     */
    private List<CmdParam<?>> inputParams;
    /**
     * 输出参数
     */
    private List<CmdParam<?>> outputParams;
    /**
     * 父节点
     */
    private StepTreeNode parentNode;
    /**
     * 子节点
     */
    private List<StepTreeNode> childNodes;

    /**
     * 构造
     *
     * @param parent 父节点
     */
    public StepTreeNode(StepTreeNode parent, Command cmd) {
        this.parentNode = parent;
        this.command = cmd;
        this.guid = UUID.randomUUID().toString();
    }

    /**
     * 添加子节点
     *
     * @param child 子节点
     */
    public void addChildNode(StepTreeNode child) {
        if (childNodes == null) {
            childNodes = new ArrayList<>();
        }
        childNodes.add(child);
    }

    /**
     * 移除子节点
     *
     * @param childId 子节点ID
     */
    public void removeChildNode(String childId) {
        if (childNodes == null) {
            return;
        }
        childNodes.removeIf(node -> node.getGuid().equalsIgnoreCase(childId));
    }

    /**
     * Get index value
     *
     * @return the index
     */
    public int getIndex() {
        return index;
    }

    /**
     * Set index to index
     *
     * @param index the index to set
     */
    public void setIndex(int index) {
        this.index = index;
    }

    /**
     * Get guid value
     *
     * @return the guid
     */
    public String getGuid() {
        return guid;
    }

    /**
     * Get name value
     *
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * Set name to name
     *
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * Get desc value
     *
     * @return the desc
     */
    public String getDesc() {
        return desc;
    }

    /**
     * Set desc to desc
     *
     * @param desc the desc to set
     */
    public void setDesc(String desc) {
        this.desc = desc;
    }

    /**
     * Get enable value
     *
     * @return the enable
     */
    public boolean isEnable() {
        return enable;
    }

    /**
     * Set enable to enable
     *
     * @param enable the enable to set
     */
    public void setEnable(boolean enable) {
        this.enable = enable;
    }

    /**
     * Get key value
     *
     * @return the key
     */
    public boolean isKey() {
        return key;
    }

    /**
     * Set key to key
     *
     * @param key the key to set
     */
    public void setKey(boolean key) {
        this.key = key;
    }

    /**
     * Get mock value
     *
     * @return the mock
     */
    public boolean isMock() {
        return mock;
    }

    /**
     * Set mock to mock
     *
     * @param mock the mock to set
     */
    public void setMock(boolean mock) {
        this.mock = mock;
    }

    /**
     * Get retry value
     *
     * @return the retry
     */
    public int getRetry() {
        return retry;
    }

    /**
     * Set retry to retry
     *
     * @param retry the retry to set
     */
    public void setRetry(int retry) {
        this.retry = retry;
    }

    /**
     * Get cmd value
     *
     * @return the cmd
     */
    public Command getCommand() {
        return command;
    }

    /**
     * Set cmd to cmd
     *
     * @param cmd the cmd to set
     */
    public void setCommand(Command cmd) {
        this.command = cmd;
    }

    /**
     * Get inputParams value
     *
     * @return the inputParams
     */
    public List<CmdParam<?>> getInputParams() {
        return inputParams;
    }

    /**
     * Set inputParams to inputParams
     *
     * @param inputParams the inputParams to set
     */
    public void setInputParams(List<CmdParam<?>> inputParams) {
        this.inputParams = inputParams;
    }

    /**
     * Get outputParams value
     *
     * @return the outputParams
     */
    public List<CmdParam<?>> getOutputParams() {
        return outputParams;
    }

    /**
     * Set outputParams to outputParams
     *
     * @param outputParams the outputParams to set
     */
    public void setOutputParams(List<CmdParam<?>> outputParams) {
        this.outputParams = outputParams;
    }

    /**
     * Get parentNode value
     *
     * @return the parentNode
     */
    public StepTreeNode getParentNode() {
        return parentNode;
    }

    /**
     * Set parentNode to parentNode
     *
     * @param parentNode the parentNode to set
     */
    public void setParentNode(StepTreeNode parentNode) {
        this.parentNode = parentNode;
    }

    /**
     * Get child Nodes
     *
     * @return the childNodes
     */
    public List<StepTreeNode> getChildNodes() {
        return childNodes;
    }

    /**
     * Set child Nodes
     *
     * @param childNodes the child Nodes to set
     */
    public void setChildNodes(List<StepTreeNode> childNodes) {
        this.childNodes = childNodes;
    }

}
